<!DOCTYPE html>
<html lang="en">
	<head>
		<title>银行网点</title>
		<#include "../inc/header.ftl"/>
	</head>

	<body class="no-skin">

		<div class="main-container ace-save-state" id="main-container">

			<div class="main-content">
				<div class="main-content-inner">

					<div class="page-content">
						<div class="row">
                            <div id="grid-main-data" class="col-xs-12">
                                <table id="MainGrid" style="min-height: 500px"></table>
								<div id="toolbar">
                                    <div style="padding:8px">
                                        区划：<input id="cantonidfind">
                                        <a href="#" onclick="javascript:searchInfo()" class="easyui-linkbutton" iconCls="icon-search">查 询</a>
                                    </div>
                                    <div style="padding:8px 8px 4px">
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="javascript:addInfo(1)">新增</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="javascript:addInfo(2)">修改</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-clear" onclick="javascript:delInfo()">删除</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-send" onclick="javascript:sendInfo()">发送</a>
                                    </div>
								</div>
							</div>
						</div><!-- /.row -->
					</div><!-- /.page-content -->
                    <div id="box-add" class="ui-dialog-content hide">
                        <form class="form-horizontal" id="form-add" method="post">
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">网点编码</label>
                                <div class="col-xs-12 col-sm-6">
									<span class="block input-icon input-icon-right">
										<input type="text" name="bankstationcode" id="bankstationcode" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
										<input type="text" name="bankstationid" id="bankstationid"  hidden style="width:100%" />
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">网点名称</label>
                                <div class="col-xs-12 col-sm-6">
                                    <div class="clearfix">
                                        <input type="text" name="bankstationname" id="bankstationname" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">区划</label>
                                <div class="col-xs-12 col-sm-6">
                                    <div class="clearfix">
                                        <input type="text" name="cantonid" id="cantonid" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div><!-- #dialog-confirm -->
                    <!-- 发送复核 -->
                    <#include "../inc/fuhe.ftl"/>
                </div>
			</div><!-- /.main-content -->
		</div><!-- /.main-container -->

		<!-- basic scripts -->
		<#include "../inc/basicjs.ftl"/>

		<!-- inline scripts related to this page -->
		<script type="text/javascript">
            //列表-------------------------------------------------
            var cantontree;
			jQuery(function($) {
				// 右侧表格
				$('#MainGrid').datagrid({
					url: prefix + '/base/basedata/findBankStationPage',
                    checkbox: true,
                    pagination: true,
                    fitColumns:false,
                    striped: true,
                    singleSelect: true,
					loadMsg: "正在加载数据，请稍后...",
					queryParams: {cantonid:''},
					columns:[[
                        { title: '区划ID',	field: 'cantonid',width:110},
                        { title: '区划编码',	field: 'cantoncode',width:100},
                        { title: '区划名称', field: 'cantonname', width: 150},
                        { title: '网点编码', field: 'bankstationcode',width: 110},
                        { title: '网点名称',	field: 'bankstationname',width:200},
                        { title: '状态', field: 'isenable', width: 100, formatter: function (value, row, index) { return (value == 1) ? "可用" : "不可用"; }}
					]],
					toolbar: '#toolbar',
                    onLoadSuccess: function (data) {
                        if (data.total == 0) {
                            $('#grid-main-data').find('.datagrid-body').html('<div style="text-align: center;font-size: 14px;padding: 20px 0;">查询无数据</div>');
                        }
                    }
				});

				$(window).resize(function() {
					$('#MainGrid').datagrid('resize');
				});
                $.ajax({
                    url:"${prefix}/base/basedata/findAllCantonMap",
                    type: 'POST',
                    async: false,
                    dataType: 'json',
                    success:function(data){
                        cantontree=data;
                    }
                });
                $('#cantonidfind').combotree({
                    data: cantontree,
                    required: true,
                    width: 200
                });
                $('#cantonid').combotree({
                    data: cantontree,
                    required: true,
                    width: 200
                });
			});

            function searchInfo() {
                $('#MainGrid').datagrid('load',{
                    cantonid: $('#cantonidfind').val(),
                });
            }

            function addInfo(opt) {
                //---区划三级下拉框
                if(opt==1){
                    $('#form-add').form('clear');
                }else{
                    var row = $('#MainGrid').datagrid('getSelected');
                    if (row == null) {
                        $.messager.alert('提示', '请选择要编辑的数据', 'info');
                        return;
                    }
                    $('#form-add').form('load',row);
                }

                $( "#box-add" ).removeClass('hide').dialog({
                    title: '&nbsp;'+(opt == 1) ? '新增' : '修改',
                    iconCls:'icon-add',
                    width: 600,
                    height: 400,
                    modal: true,
                    buttons:[{
                        text:(opt == 1) ? '新增' : '修改',
                        iconCls:'icon-ok',
                        width:80,
                        plain:false,
                        handler:function(){
                            saveInfo(opt);
                        }
                    },{
                        text:'取消',
                        iconCls:'icon-cancel',
                        width:80,
                        plain:false,
                        handler:function(){$('#box-add').dialog('close')}
                    }]
                });
            }

            function delInfo() {
                row = $('#MainGrid').datagrid('getSelected');
                if (row == null) {
                    $.messager.alert('提示', '请选择要删除的数据', 'info');
                    return;
                }

                $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
                    if (r){
                        $.ajax({
                            url: prefix +'/base/basedata/deleteBankStation',
                            type: 'POST',
                            data: {bankstationid:row.bankstationid},
                            dataType: 'json',
                            success:function(data){
                                searchInfo();
                                $.messager.alert('提示', data.msg, 'info');
                            }
                        });
                    } else{//没选中
                        return false;
                    }
                })
            }

            function saveInfo(opt) {
                var url = (opt == 1) ? '/base/basedata/saveBankStation' : '/base/basedata/updateBankStation'
                $('#form-add').form({
                    url: prefix +url,
                    onSubmit:function(param){
                        var isValid = $(this).form('validate');
                        if (isValid){
                            $.messager.progress({
                                title: '提示',
                                msg: '数据处理中，请稍候……',
                                text: ''
                            });
                        }
                        return isValid;
                    },
                    success:function(data) {
                        $.messager.progress('close');
                        var data = eval('(' + data + ')');
                        if(data.success) {
                            $('#form-add').form('load',data.data);
                            $('#box-add').dialog('close');
                            searchInfo();
                        }
                        $.messager.alert('提示', data.msg, 'info');
                    }
                });
                $('#form-add').submit();
            }

            //----------------------- 发送弹窗
            function sendInfo() {
                    send_tit = "发送";
                    send_url = "/base/basedata/sendBankStation";
                    send_reload = 0;
                openSendBox();
                var row = $('#SendMainGrid').datagrid('getData');
                $.each(row.rows,function(index, value) {
                    value.billid = value.bankstationid
                });
            }

        </script>
	</body>
</html>
